<?php 

include("header.php");
include("thumb.php");
#include("banners/main-left-banner.php");
?>

</td><td class="main-td">

<div id="main-div" class="main-div">

<?php 

$settings = array('w'=>300,'h'=>300,'crop'=>true); 
$settings2 = array('w'=>1200,'h'=>400); 
$settings3 = array('w'=>125,'h'=>150, 'crop'=>true); 


$siteId = null;
if (isset($_GET["site"])) {
	$siteId = htmlspecialchars($_GET["site"]);
}
$catId = null;
if (isset($_GET["cat"])) {
	$catId = htmlspecialchars($_GET["cat"]);
}


if ($gconfig['slideshow-enabled']) {
	
	$query='SELECT * FROM slideshow_v';
	$query=$query." where id = ".$gconfig['slideshow'];
	
	$mainresult=mysql_query($query);
	$num=mysql_numrows($mainresult);

	$slideshow_links = array();

	$i=0;
	while ($i < $num) {
		$imagedir=mysql_result($mainresult,$i,"imagedir");
		$gid=mysql_result($mainresult,$i,"gallery_id");
		$index=mysql_result($mainresult,$i,"index");
		$fullpath=$gconfig['image-root']."/".$imagedir;
		
		$files = scandir($fullpath);
		natsort($files);
		$files=array_values($files);
		
		$file = $files[$index+1];
		$imagepath = $fullpath."/".$file;
	       
	  	$link = '<a class="main-image-link" href="show-'.$gid.'">';
	  	$link = $link.'<div id="main-image-div" name="image-div" class="main-image-div main-image-landscape';
	  	$link = $link.'" style="background-image: url('.resize($imagepath,$settings2).')"></div></a>';
	  	
	  	$slideshow_links[$i] = $link;
	  	$i++;
	}
	
	echo '<div id="slideshow-div">';
	if ($gconfig['slideshow-auto']) {
		echo $slideshow_links[0];
	}
	else {
		$randint = rand(0, count($slideshow_links)-1);
		echo $slideshow_links[$randint];
	}
	echo '</div>';
}

include('title_bar.php');


$query="SELECT g.id, g.name, g.desc, gt.path
	FROM gallery g
	join gallery_thumb gt on gt.gallery_id = g.id
	where gt.thumb_size = 1";

if ($catId != null) {
	$query=$query." and cat_id = '".$catId."'";
}

$query=$query.' order by g.added desc limit '.$gconfig['big-galleries'];

$result=mysql_query($query);

$num=mysql_numrows($result);

$i=0;
while ($i < $num) {

	$id=mysql_result($result,$i,"id");
	$name=mysql_result($result,$i,"name");
	$desc=mysql_result($result,$i,"desc");
	$imagepath=mysql_result($result,$i,"path");
	
    echo '<div class="image-frame-div"><table class="image-frame-table"><tr><td>';
  	echo '<a class="main-image-link" href="show.php?id='.$id.'">';
   	   	   	
    echo '<div name="image-div" class="image-div">';  	
    echo '<img src="'.$imagepath.'" alt="'.$name.'"/>';  	
    echo '</div>';
    echo "</a></td></tr><tr><td>";
    echo '<div class="image-desc-div">';
    echo '<p class="image-name-span">'.$name.'</p>';
    echo '<p class="image-desc-span">'.$desc.'</p>';
    echo '</div>';
    echo "</td></tr></table></div>";
	
	$i++;
}

?>


<?php 



$query="SELECT g.id, g.name, g.desc, gt.path
	FROM gallery g
	join gallery_thumb gt on gt.gallery_id = g.id
	where gt.thumb_size = 2";

if ($catId != null) {
	$query=$query." and cat_id = '".$catId."'";
}

$query=$query.' order by added desc limit '.$gconfig['tiny-galleries'].' offset '.$gconfig['big-galleries'];

$result=mysql_query($query);

$num=mysql_numrows($result);

$i=0;
while ($i < $num) {

	$id=mysql_result($result,$i,"id");
	$name=mysql_result($result,$i,"name");
	$desc=mysql_result($result,$i,"desc");
	$imagepath=mysql_result($result,$i,"path");
	
    echo '<div class="tiny-image-frame-div">';
  	echo '<a class="main-image-link" href="show.php?id='.$id.'">';   	   	   	
    echo '<div name="image-div" class="tiny-image-div">';    	
    echo '<img src="'.$imagepath.'" alt="'.$name.'"/>';
    echo '</div>';
    echo "</a>";
    echo "</div>";
	
	$i++;
}

?>




<script type="text/javascript">

	function loadAnotherPage(n)
	{
	
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    document.getElementById("main-div").innerHTML+=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","page.php?page="+n,true);
		xmlhttp.send(); 
	}
	
	var contentHeight = 1450;  
	var pageHeight = document.documentElement.clientHeight;  
	var scrollPosition;  
	var n = 1;
	
	function scroll(){  
		  
	    if(navigator.appName == "Microsoft Internet Explorer") { 
	        scrollPosition = document.documentElement.scrollTop;
	    }  
	    else {  
	        scrollPosition = window.pageYOffset;          
	    }
	  
	    if((contentHeight - pageHeight - scrollPosition) < 200){  
	  
	        if(window.XMLHttpRequest)  {
	            xmlhttp = new XMLHttpRequest();  
	        }
	        else  {
	            if(window.ActiveXObject)  {
	                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	            } 
	            else {  
	                alert ("Bummer! Your browser does not support XMLHTTP!");           
	            }
	        }
	  
	        
	        loadAnotherPage(n);
	        n += 1;  
	        contentHeight += 1500;  
	    }  
	}  


	var mainindex = 0;
	var mainimages = new Array();
<?php 
	$i=0;
	while ($i < count($slideshow_links)) { 
		echo "mainimages[$i] = '$slideshow_links[$i]';";
		$i++;
	}
?>

	function updateSlide() {
		mainindex++;
		if (mainindex >= mainimages.length) {
			mainindex = 0;
		}
		document.getElementById('slideshow-div').innerHTML  = mainimages[mainindex];
	}

	<?php if ($gconfig['slideshow-enabled'] && $gconfig['slideshow-auto']) { ?>
	setInterval("updateSlide()",2500);
	<?php } ?>

	<?php if (isset($gconfig['style']) && $gconfig['style'] == 'infinite') { ?>
	setInterval('scroll();', 250);">  
	<?php } ?>

</script>

</div>
</td><td valign="top" width="125px">

<?php 

#include("banners/main-right-banner.php");
include("footer.php");

?>